<template>
  <window ref="win" title="预设老师状态">

  <div>
      <div class="g-job">
        <el-checkbox v-model="checkJobNature"></el-checkbox>
        <div class="g-job-select">
            <el-select v-model="jobNature" placeholder="请选择任教性质">
              <el-option
                key="0"
                label="普通"
                value="0">
              </el-option>
              <el-option
                key="1"
                label="指导"
                value="1">
              </el-option>
              <el-option
                key="2"
                label="内部兼课"
                value="2">
              </el-option>
            </el-select>

        </div>
        <div class="g-job-picker">
          <el-date-picker
            v-model="jobNatureHappenDate"
            type="date"
            placeholder="生效日期">
          </el-date-picker>
        </div>
      </div>
      <div class="g-status">
        <el-checkbox v-model="checkStatus"></el-checkbox>
        <div class="g-status-select">
          <el-select v-model="status" placeholder="请选择在职状态">
            <el-option
              key="0"
              label="离职"
              value="0">
            </el-option>
            <el-option
              key="1"
              label="在职"
              value="1">
            </el-option>
          </el-select>
        </div>
        <div class="g-status-picker">
          <el-date-picker
            v-model="statusHappenDate"
            type="date"
            placeholder="生效日期">
          </el-date-picker>
        </div>
      </div>
      <div class="g-change-btn">
        <el-button  @click="cancel" >取消</el-button>
        <el-button @click="save">确定</el-button>
      </div>
    </div>
  </window>
</template>
<script>
  import io from '../../lib/io'
  import util from '../../lib/util'

  export default{
    data: function () {
      return {
        statusHappenDate:'',
        jobNatureHappenDate:'',
        status:'',
        jobNature:'',
        checkJobNature:false,
        checkStatus:false,
        teacher:{}
      }
    },
    components: {

    },
    mounted: function () {
    },
    created: function () {


    },
    methods: {
      loadTableData:function(){
        var _this = this
        io.post(io.apiAdminDelayTeacherMessage,{ teacherId : _this.teacher.teacherId },
          function(ret){
            if(ret.success && ret.data){
              ret.data.map(function(item) {
                if (item.changeType==1){
                  _this.checkStatus=true;
                  _this.status=item.changeData
                  _this.statusHappenDate=util.formatDate(item.happenDate)
                }else if (item.changeType==2){
                  _this.checkJobNature=true;
                  _this.jobNature=item.changeData
                  _this.jobNatureHappenDate=util.formatDate(item.happenDate)
                }
              })
            }
          },
          function(){
            _this.$alert('请求服务器失败')
          })
      },
      show:function(){
        var _this  = this
        _this.statusHappenDate=''
        _this.jobNatureHappenDate=''
        _this.status=''
        _this.jobNature=''
        _this.checkJobNature=false
        _this.checkStatus=false
        this.loadTableData()
        this.$refs.win.show({
          width:1000,
          height:600
        })
      },
      cancel:function () {
        var _this  = this
        _this.$refs.win.close()
      },
      save:function () {
        var paramArray=[]
        var _this  = this
        if( _this.checkJobNature==false &&  _this.checkStatus==false){
          _this.$alert('必须选择一项进行更改')
          return false
        }
        if(_this.checkJobNature){
          var param={}
          param.changeType=2
          param.happenDate=this.$options.filters.formatDate(_this.jobNatureHappenDate)
          param.changeData=_this.jobNature
          paramArray.push(param);
        }
        if(_this.checkStatus){
          var param={}
          param.changeType=1
          param.happenDate=this.$options.filters.formatDate(_this.statusHappenDate)
          param.changeData=_this.status
          paramArray.push(param);
        }
        io.post(io.apiAdminSaveDelayUpdateTeacher,{
          teacherId : _this.teacher.teacherId ,
          delayChangeTeacherVos : JSON.stringify(paramArray)
        },function(ret){

          if(ret.success){
            _this.$emit('completed')
            _this.$refs.win.close()
          }else{
            _this.$alert(ret.desc ||  '处理失败')
          }
        })
      }
    }
  }
</script>
<style lang="less">
  .g-status{
    padding-top:20px;
    .el-checkbox{
      margin-right:30px;
    }
    .g-status-select{
      display:inline-block;
      margin-right:30px;

    }
    .g-status-picker{
      width:191px;
      display:inline-block;

    }
  }
  .g-job{
    padding-top:20px;
    .el-checkbox{
      margin-right:30px;
    }
    .g-job-select{
      display:inline-block;
      margin-right:30px;
    }
    .g-job-picker{
      width:191px;
      display:inline-block;
    }
    .g-change-btn{
      padding:20px;
      .el-button{
        width:100px;
        height:36px;
      }
    }
  }
  .g-change-btn{
    padding:20px;
    .el-button{
      width:100px;
      height:36px;
      background:#23abf0;
      color:#fff;
      border:0 none;
    }
  }
</style>
